import request from '@/config/axios'
import type { Dayjs } from 'dayjs'

/** 模具维修任务信息 */
export interface RepairJob {
  id: number // 主键
  code?: string // 单号
  accountId?: number // 模具台账ID
  repairCategoryId?: number // 维修分类Id
  faultId?: number // 故障分类Id
  applicantId?: number // 申请人ID
  departId?: number // 申请部门
  applicationTime?: string | Dayjs // 申请时间
  faultDescription: string // 故障描述
  status: number // 状态
}

export interface RepairJobModStatus {
  id: number // 主键
  status: number // 任务状态
  data?: string // 参数
}

export interface RepairJobWorkReport {
  id: number
  repairCategoryId: string
  repairerIds: number[]
  jobStartTime: string
  jobEndTime: string
  jobExecutionDuration: number
  description: string
  repairCost: number
}

// 模具维修任务 API
export const RepairJobApi = {
  // 查询模具维修任务分页
  getRepairJobPage: async (params: any) => {
    return await request.get({ url: `/mold/repair-job/page`, params })
  },

  // 查询模具维修任务详情
  getRepairJob: async (id: number) => {
    return await request.get({ url: `/mold/repair-job/get?id=` + id })
  },

  // 新增模具维修任务
  createRepairJob: async (data: RepairJob) => {
    return await request.post({ url: `/mold/repair-job/create`, data })
  },

  // 修改模具维修任务
  updateRepairJob: async (data: RepairJob) => {
    return await request.put({ url: `/mold/repair-job/update`, data })
  },

  // 删除模具维修任务
  deleteRepairJob: async (id: number) => {
    return await request.delete({ url: `/mold/repair-job/delete?id=` + id })
  },

  /** 批量删除模具维修任务 */
  deleteRepairJobList: async (ids: number[]) => {
    return await request.delete({ url: `/mold/repair-job/delete-list?ids=${ids.join(',')}` })
  },

  // 导出模具维修任务 Excel
  exportRepairJob: async (params) => {
    return await request.download({ url: `/mold/repair-job/export-excel`, params })
  },

  // 修改模具维修任务状态
  modStatus: async (data: RepairJobModStatus) => {
    return await request.put({ url: `/mold/repair-job/mod-status`, data })
  },
  // 提交工作报表
  submitWorkReport: async (data: RepairJobWorkReport) => {
    return await request.put({ url: `/mold/repair-job/work-report`, data })
  }
}
